﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pardusshipcalc
{
    class MiscMath
    {
        /// <summary>
        /// Allows you to round to a certain power. -2 will round to nearest 100, -3 to nearest 1000.
        /// </summary>
        /// <param name="value">Value to round.</param>
        /// <param name="digits">How many digits to round to.</param>
        /// <returns></returns>
        public double Round(double value, int digits)
        {

            if ((digits < -15) || (digits > 15))

                throw new ArgumentOutOfRangeException("digits", "Rounding digits must be between -15 and 15, inclusive.");



            if (digits >= 0)

                return Math.Round(value, digits);



            double n = Math.Pow(10, -digits);

            return Math.Round(value / n, 0) * n;

        }
    }
}
